package com.hui.li.controller;

import com.hui.li.entity.User;
import com.hui.li.util.AsyncFactory;
import com.hui.li.util.AsyncManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @projectName: Spring-RestTemplate
 * @package: com.hui.li.controller
 * @className: PhoneTest
 * @author: Hui
 * @date: 2021/12/22 21:52
 */
@RestController
public class PhoneTest {

    //required = false去除波浪线
    @Autowired(required=false)
    private AsyncManager asyncManager;

    @GetMapping("sendCode")
    public String send(){
         String phone = "123456";
         String code = "123456";
        System.out.println(phone);
        System.out.println(code);
         asyncManager.execute(AsyncFactory.sendCode(phone,code));
        System.out.println("===执行了......");
        return "success";
    }


    @GetMapping("hui/{phone}")
    public String phone(@PathVariable String phone){
        System.out.println(phone);
        return "success";
    }

    @PostMapping("hui")
    public String user1(@RequestBody User user){
        System.out.println(user);
        return "success";
    }
    @PutMapping("hui1")
    public String put1(@RequestBody Map<String,Object> map){
        System.out.println(map);
        return "success";
    }

    @DeleteMapping("hui02/{key}")
    public String deleteHui(@PathVariable String key){
        System.out.println(key);
        String[] split = key.split(",");
        List<String> strings = Arrays.asList(split);
        strings.forEach(s -> {
            //把数字的字符串类型转换为Int类型
            Integer integer = Integer.valueOf(s);
            //根据主键进行删除
            System.out.println(integer);
        });
        return "success";
    }
}
